<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <link rel="shortcut icon" href="../images/favicon.ico">
    <link rel="apple-touch-icon-precomposed" href="../images/apple-touch-icon.png">
    <title>timepart</title>
    <link rel="stylesheet" href="../../dist/seedsui.min.css">
    <style>
    .SID-Custom{
        background-color: #4DDB63;
    }
    </style>
</head>

<body ontouchstart="">
<section>
	<header>
        <div class="titlebar">
            <a class="titlebar-button" href="javascript:back()">
                <i class="icon icon-arrowleft"></i>
            </a>
            <h1 class="titlebar-title">时间段控件</h1>
        </div>
    </header>
	<article>
        <div class="timepart group" id="ID-Timepart"></div>
        <a class="button block" style="margin:8px;border-radius: 4px;" id="ID-BtnDisable">禁用当前时间</a>
        <a class="button block" style="margin:8px;border-radius: 4px;" id="ID-BtnDisableCustom">禁用17:00到18:00</a>
        <a class="button block" style="margin:8px;border-radius: 4px;" id="ID-BtnCustom">选择9:10到12:10</a>
        <a class="button block" style="margin:8px;border-radius: 4px;" id="ID-BtnSubmit">预约</a>
        <a class="button block" style="margin:8px;border-radius: 4px;" id="ID-BtnReset">重置</a>
	</article>
</section>
    <script src="../../dist/seedsui.min.js"></script>
	<script>
        var view={
            /*=========================
              Model
              ===========================*/
            render:function(){
                var self = this;
                //提示框
                this.toast=new Toast();
                //时间段
                this.part1,this.part2;
                this.timepart=new Timepart("#ID-Timepart",{
                    startTime:"7:00",
                    endTime:"22:00",
                    onClick:function(e){
                        console.log(e.target);
                    },
                    onConflictOver:function(e){
                        console.log("不能跨选禁用时间段");
                        console.log(e.target);
                    },
                    onConflictContain:function(e){
                        console.log("时间段冲突");
                        console.log(e.target);
                    },
                    onClickActive:function(e){
                        console.log("点击选中区域");
                        e.removeAllActive();
                    },
                    onClickDisabled:function(e){
                        console.log("点击禁用区域");
                    },
                    onClickChoose:function(e){
                        console.log();
                        var data=JSON.parse(e.target.getAttribute("data-progress"));
                        console.log("点击选择区域，数据：{startTime:"+data.startTime+",endTime:"+data.endTime+"}");
                    },
                    onClickValid:function(s){//点击有效区域
                        if(s.clickCount==1){//如果点击了一次
                            self.part1=s.target;
                            self.part1.classList.add(s.params.activeClass);
                        }else if(s.clickCount==2){//如果点击了两次
                            self.part2=s.target;
                            //选中
                            var times=s.getTimesByParts(self.part1,self.part2);
                            s.activeTimes(times.startTime,times.endTime);
                        }else if(s.clickCount==3){//如果点击了三次
                            s.removeAllActive();
                        }
                    },
                });
                //this.timepart.disableTimes("07:00","21:00");
                self.timepart.chooseTimes("11:10","12:10",["SID-Custom"]);
                //this.timepart.activeTimes("07:00","08:00");
                //加载数据
                this.loadData();
            },
            refresh:function(){
                console.log("刷新");
            },
            destroy:function(){
                console.log("移除");
            },
            loadData:function(){

                this._attach();//使用backbone时，此行无用
            },
            /*=========================
              Events
              ===========================*/
            _attach:function(e){
                var self=this;
                
                document.getElementById("ID-BtnDisable").addEventListener("click",function(e){
                    self.timepart.disableTimes(null,new Date());
                },false);

                document.getElementById("ID-BtnDisableCustom").addEventListener("click",function(e){
                    self.timepart.disableTimes("17:10","18:10");
                },false);
                
                document.getElementById("ID-BtnCustom").addEventListener("click",function(e){
                    var data=JSON.stringify({startTime:"3:00",endTime:"5:00"});
                    self.timepart.chooseTimes("9:10","12:10",["SID-Custom"],data);
                },false);

                document.getElementById("ID-BtnSubmit").addEventListener("click",function(e){
                    var times=self.timepart.getActiveTimes();
                    var starttime=times.startTimeString;
                    var endtime=times.endTimeString;
                    console.log("选中时间："+starttime+" ~ "+endtime);
                },false);
                
                document.getElementById("ID-BtnReset").addEventListener("click",function(e){
                    self.timepart.reset();
                },false);
            },
            /*=========================
              Event Handler
              ===========================*/
        }

        window.addEventListener("load",function(){
            view.render();
        }, false);

		//定义exmobi返回
		function back() {
			history.go(-1);
		}
	</script>
</body>
</html>